﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DHQGHN.DAL.Common;
using DHQGHN.DAL.DAO.Admin;
using DHQGHN.DAL.Models.Admin;

namespace DHQGHN.DAL.BO.Admin
{
    public class ReligionBO : BaseBO
    {
        public const string FIELD_RELIGION_ID = "RELIGION_ID";
        public const string FIELD_NAME = "NAME";
        public const string FIELD_CODE = "CODE";
        public const string FIELD_DESCRIPTIONS = "DESCRIPTIONS";
        public const string FIELD_DELETED = "DELETED";
        public const string Field_RECORD_COUNT = "RecordCount";

        private String _connectionString;

        public ReligionBO(string connString)
        {
            this._connectionString = connString;

        }
        public ReligionBO()
        {
            this._connectionString = Common.ConnectionUtil.TKTHDS_METADATA_CONNECTION_STRING;

        }

        public ReligionDAO _religionDAO;

        public ReligionDAO CreateSQLDAO()
        {
            return new ReligionDAO(_connectionString, DEFAULT_MAPPER_TYPE);
        }

        public DataPage<ReligionModel> GetDynamicListPaging(ReligionModel rModel, int pageSize, int pageIndex,bool compareEqual)
        {
            try
            {
                _religionDAO = CreateSQLDAO();
                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {
                    {ReligionModel.FIELD_RELIGION_ID,FIELD_RELIGION_ID},
                    {ReligionModel.FIELD_NAME,FIELD_NAME},
                    {ReligionModel.FIELD_CODE,FIELD_CODE},  
                    {ReligionModel.FIELD_DESCRIPTIONS,FIELD_DESCRIPTIONS},
                    {ReligionModel.FIELD_DELETED,FIELD_DELETED},                    
                    {ReligionModel.FIELD_RECORD_COUNT,Field_RECORD_COUNT}
                    
                };
                return _religionDAO.GetDynamicListPaging(rModel, pageSize, pageIndex, mapDictionary,compareEqual);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public ReligionModel GetReById(string religion_Id)
        {
            try
            {
                _religionDAO = CreateSQLDAO();

                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {
                    {ReligionModel.FIELD_RELIGION_ID,FIELD_RELIGION_ID},
                    {ReligionModel.FIELD_NAME,FIELD_NAME},
                    {ReligionModel.FIELD_CODE,FIELD_CODE},  
                    {ReligionModel.FIELD_DESCRIPTIONS,FIELD_DESCRIPTIONS},
                    {ReligionModel.FIELD_DELETED,FIELD_DELETED}
                    
                };

                return _religionDAO.GetById(religion_Id, mapDictionary);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public bool createOrUpdateReligion(ReligionModel reModel)
        {
            try
            {
                _religionDAO = CreateSQLDAO();
                return _religionDAO.createOrUpdateReligion(reModel);
            }
            catch (Exception e)
            {
                return false;
            }
        }

        public bool deleteReligion (string[] religion_Id)
        {
            try
            {
                _religionDAO = CreateSQLDAO();
                return _religionDAO.deleteReligion(religion_Id);
            }
            catch (Exception e)
            {
                return false;
            }
        }

        public DataPage<ReligionModel> GetDynamicListPagingd(ReligionModel rModel, int pageSize, int pageIndex, bool compareEqual)
        {
            try
            {
                _religionDAO = CreateSQLDAO();
                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {
                    {ReligionModel.FIELD_RELIGION_ID,FIELD_RELIGION_ID},
                    {ReligionModel.FIELD_NAME,FIELD_NAME},
                    {ReligionModel.FIELD_CODE,FIELD_CODE},  
                    {ReligionModel.FIELD_DESCRIPTIONS,FIELD_DESCRIPTIONS},
                    {ReligionModel.FIELD_DELETED,FIELD_DELETED},                    
                    {ReligionModel.FIELD_RECORD_COUNT,Field_RECORD_COUNT}
                    
                };
                return _religionDAO.GetDynamicListPagingd(rModel, pageSize, pageIndex, mapDictionary, compareEqual);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public bool reActive(string appId)
        {
            try
            {
                _religionDAO = CreateSQLDAO();
                return _religionDAO.reActive(appId);
            }
            catch (Exception e)
            {
                return false;
            }
        }
    }
}
